<template>
  <div>
    <!--图表概览-->
    <el-row :gutter="10" style="margin-bottom: 40px">
      <el-col :span="6">
        <el-card style="color: #409EFF">
          <div><i class="el-icon-user-solid" /> 用户总数</div>
          <div style="padding: 10px 0; text-align: center; font-width: bold;">100</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #F56C6C">
          <div><i class="el-icon-s-goods" /> 销售总量</div>
          <div style="padding: 10px 0; text-align: center; font-width: bold;">￥ 1000000</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #67C23A">
          <div><i class="el-icon-coin" /> 收益总额</div>
          <div style="padding: 10px 0; text-align: center; font-width: bold;">￥ 300000</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #E6A23C">
          <div><i class="el-icon-s-shop" /> 门店总数</div>
          <div style="padding: 10px 0; text-align: center; font-width: bold;">100</div>
        </el-card>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <!--折线图-->
        <div id="main" style="width: 500px;height: 400px;">
          <el-card >
          </el-card>
        </div>
      </el-col>

    <el-col :span="12">
      <!--饼图-->
      <div id="main2" style="width: 500px;height: 400px;">
        <el-card>
        </el-card>
      </div>
    </el-col>

    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: "Home",
  data(){
    return{

    }
  },
  mounted() {
    //折线图

    var option;
    option = {
      title: {
        text: '各季度会员数量统计',
        subtext: '趋势图',
        left:'38%',
        top:'95%',

      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'cross',
          label: {
            backgroundColor: '#6a7985'
          }
        }
      },
      legend: {
        data: ["第一季度", "第二季度", "第三季度", "第四季度"]
      },
      toolbox: {
        feature: {
          saveAsImage: {}
        }
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: [
        {
          type: 'category',
          boundaryGap: false,
          data: ["第一季度", "第二季度", "第三季度", "第四季度"]
        }
      ],
      yAxis: [
        {
          type: 'value'
        }
      ],
      series: [
        {
          name: '第一季度',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: []
        },
        {
          name: '第二季度',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: []
        },
        {
          name: '第三季度',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: []
        },
        {
          name: '第四季度',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: []
        },

      ]
    };


    //饼图
    var circleOption;
    circleOption = {
      title: {
        text: '各季度会员数量比例图',
        // subtext: 'Fake Data',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        bottom: 'bottom'
      },
      series: [
        {
          name: '会员数量',
          type: 'pie',
          radius: '50%',
          center: ['50%', '50%'],
          label:{            //饼图图形上的文本标签
            normal:{
              show:true,
              position:'inner', //标签的位置
              textStyle : {
                fontWeight : 300 ,
                fontSize : 14,    //文字的字体大小
                color: "#fff"
              },
              formatter:'{d}%'
            }
          },
          data: [],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };




    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);

    //饼图
    var circleChartDom = document.getElementById('main2');
    var circleMyChart = echarts.init(circleChartDom);

    this.$axios.get("/echarts/members").then(res=>{
      let i=0
      // option.xAxis.data=res.data.data.x
       while(i!=option.series.length){
         // res.data.data.y.forEach(data=>{
         //   option.series[i++].data=data
         // })
           option.series[i++].data=res.data.data
       }
      option && myChart.setOption(option);

      circleOption.series[0].data=[
        {name:'第一季度',value:res.data.data[0]},
        {name:'第二季度',value:res.data.data[1]},
        {name:'第三季度',value:res.data.data[2]},
        {name:'第四季度',value:res.data.data[3]}
      ]

      circleOption && circleMyChart.setOption(circleOption);
    })

  }
}
</script>

<style scoped>

</style>